### Install and load all relevant packages for all analyses ###

# List of packages to load
packages <- c(
  "tidyverse", "rdd", "jtools", "tidyr", "ggpubr", 
  "rddtools", "sensemakr", "sandwich", "lmtest", 
  "quanteda", "stm", "seededlda", "topicmodels", 
  "vader", "rvest", "stringr", "haven", "texreg", "stargazer", "rdpower", "factoextra"
)

# Function to check and install packages
install_and_load <- function(package_name) {
  if (!requireNamespace(package_name, quietly = TRUE)) {
    install.packages(package_name, dependencies = TRUE)
  }
  library(package_name, character.only = TRUE)
}

# Load and install packages
lapply(packages, install_and_load)

devtools::install_github("kbenoit/quanteda.dictionaries") # install this one separately
library(quanteda.dictionaries) # load this one separately

